package com.trainoo.eurakaconsumer.service;

import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * @Auther: zt
 * @Date: 2019/12/3 17:35
 * @Description: hystrix 服务降级
 */
@Service
public class ConsumerService {
    @Autowired
    RestTemplate restTemplate;

    /**
     * 如果请求不到 eureka-client/dc, 则会执行 fallback 方法
     */
    @HystrixCommand(fallbackMethod = "fallback")
    public String consumer() {
        return restTemplate.getForObject("http://eureka-client/dc", String.class);
    }

    public String fallback() {
        return "fallback";
    }
}
